package com.whosly.fast.web.quickly.common;

import lombok.Getter;

import java.util.Optional;

@Getter
public class ServiceException extends RuntimeException {

    private final ErrorCode rcode;
    private final String rmsg;

    /**
     * 异常根因
     */
    private final Optional<Throwable> causeInfo;

    public ServiceException(ErrorCode rcode, String rmsg) {
        super(rmsg);
        this.rcode = rcode;
        this.rmsg = rmsg;
        this.causeInfo = Optional.empty();
    }

    public ServiceException(ErrorCode rcode, Throwable rmsg) {
        super(rmsg);
        this.rcode = rcode;
        this.rmsg = rmsg.getMessage();
        this.causeInfo = Optional.of(rmsg);
    }

}
